package demo.hdz.testui;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author hdz
 * @date 2018/07/04
 */
public class JumpActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jump);

        TextView textView = (TextView) findViewById(R.id.tvTitle);
        textView.setText("Activity 跳转");

        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        int age = intent.getIntExtra("age", -1);

        TextView tvReceiveName = (TextView) findViewById(R.id.tvReceiveName);
        tvReceiveName.setText(name);
        TextView tvReceiveAge = (TextView) findViewById(R.id.tvReceiveAge);
        tvReceiveAge.setText(""+age+"");

        Button btnBack = (Button) findViewById(R.id.btnBack);
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //由于这里不用实现页面跳转，所以不用context和class参数
                Intent intent = new Intent();

                EditText etBackName = (EditText) findViewById(R.id.etBackName);
                String name = etBackName.getText().toString();
                EditText etBackAge = (EditText) findViewById(R.id.etBackAge);
                int age = Integer.parseInt("0"+etBackAge.getText().toString());

                //putExtra方法将数据以键值对的方式储存起来，第一个参数是“健”，第二个就是“值”。
                //这里将回传数据作为值传进去。
                intent.putExtra("name", name);
                intent.putExtra("age", age);

                //在这里将resultCode定义为2，并将intent作为内容传进去
                setResult(Constant.JUMP_RESULT_CODE, intent);

                //最后调用`finish()`方法关闭当前activity，直接返回FActivity
                finish();
            }
        });
    }
}
